<?php

namespace Wanecho\FlarumAdnet\Controllers\Api;

use Flarum\User\User;
use Psr\Http\Message\ServerRequestInterface;
use Wanecho\FlarumAdnet\AdslistModel;
use Tobscure\JsonApi\Document;
use Flarum\Api\Serializer\UserSerializer;
use Laminas\Diactoros\Response\JsonResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Server\RequestHandlerInterface;

class LooknumsController implements RequestHandlerInterface
{


    public function handle(ServerRequestInterface $request): ResponseInterface
    {
 
        $actor = $request->getAttribute('actor');
        if($actor->id){
            $today = new \DateTime('now');
            $nums = AdslistModel::where('user_id',$actor->id)->whereDate('created_at',$today->format('Y-m-d'))->count();
            return new JsonResponse(['haslook'=>$nums]);
        } 
        return new JsonResponse(['haslook'=>0]);  
    }
}

